package April.Twenty_six;

import java.sql.*;

/*
PrepareStatement 接口的实现类数据表的查询操作
 */
public class JdbcDemo_4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://127.0.0.1:3306/myBase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
        String userName = "root";
        String password = "123";
        Connection con = DriverManager.getConnection(url, userName, password);

        String sql = "SELECT * FROM zhangwu";

        PreparedStatement pst = con.prepareStatement(sql);

//        调用pst对象的方法，执行查询语句，select
        ResultSet rs = pst.executeQuery();
        while(rs.next()){
            System.out.println(rs.getString("id")+"  "+rs.getString("name")+" " +
                    " "+rs.getString("money"));
        }

        rs.close();
        pst.close();
        con.close();

    }
}
